#ifndef SHAPES_H
#define SHAPES_H

#include <string.h>
#include "Def.h"
#include "Nodes.h"

class Shapes{
		
	public:
				
		bool parse(string fileName){
			
			ifstream inp(fileName.c_str());
			if(!inp.is_open()){
				cerr<<"Can not open "<<fileName<<endl;
				exit(1);
			}
			
			char line[1024];
			char name[256];
			Node *node;
			NODE_ITERATOR it;
			int numNodes;
			int numShapes;
				
			for(int i=0; i<4; ++i)
				inp.getline(line, 1024);
			
			inp.getline(line, 1024);
			sscanf(line, "NumNonRectangularNodes  :  %d", &numNodes);
			inp.getline(line, 1024);
			cout<<"Number of non-rectangular nodes: "<<numNodes<<endl;
			for(int i=0; i<numNodes; ++i){
				inp.getline(line, 1024);
				sscanf(line, "%s  :  %d", name, &numShapes);
				node = new Node;
				node->name = name;
				it = nodes.nodes.find(node);
				if(it==nodes.nodes.end())
					it = nodes.terminals.find(node);
				if(it==nodes.terminals.end()){
					cerr<<"Not found Node"<<name<<endl;
					exit(1);
				}
				delete node;
				node = *it;
				node->shapes.resize(numShapes);
				for(int j=0; j<numShapes; ++j){
					inp.getline(line, 1024);
					sscanf(line, "        %s        %d        %d         %d           %d", 
						name, &node->shapes[j].ll_xcoord,&node->shapes[j].ll_ycoord,
						&node->shapes[j].width,&node->shapes[j].height);
					node->shapes[j].id = j;
				}
			}		
			inp.close();
			return true;
		}
	};	
				
	extern Shapes shapes;
				
#endif

